{extend name="platform/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="__STATIC__/blue/css/ns_table_style.css">
<style>
p{margin: 0;}
.hint{line-height: 34px;}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 添加钩子</header>
	<div class="panel-body">
		<form class="form-horizontal" id="form" name="form" onsubmit="">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="color-red">*</span>钩子名称</label>
				<div class="col-md-3">
					<input type="text" class="form-control" id="name" value="" onkeydown="hooks_error()">
				</div>
				<p class="error">请输入钩子名称</p>
				<p class="hint">需要在程序中先添加钩子，否则无效</p>
				
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">钩子描述</label>
				<div class="col-md-3">
					<textarea id="desc" class="input-common" style="max-width: 100%;min-width: 100%; max-height: 200px;"></textarea>
				</div>
				<p class="hint">钩子的描述信息</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>

			<div class="form-group">
				<label class="col-sm-2 control-label">钩子类型</label>
				<div class="col-md-2">
					<select id="type" class="select-common form-control">
					<option value="1">视图</option>
					<option value="2">控制器</option>
				</select>
				</div>
				<p class="hint">区分钩子的主要用途</p>
			</div>

			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="save()" class="btn btn-primary">确定</a>
				</div>
			</div>
		</form>
	</div>
</section>
<script>
//添加广告位
function save() {
	var name = $("#name").val();
	var desc = $("#desc").val();
	var type = $("#type").val();
	if(verify(name)){
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/extend/addHooks')}",
			data : {
				'name' : name,
				'desc' : desc,
				'type' : type,
			},
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "添加成功","{:__URL('PLATFORM_MAIN/extend/hookslist')}");
				}else{
					showMessage('error', "添加失败");
				}
			}
		});
	}
}
function hooks_error(){
	$(".error").hide();
	$("#name").parent().nextAll(".hint").show();
}
function verify(name){
	if(name == ''){
		$("#name").parent().next(".error").show();
		$("#name").parent().nextAll(".hint").hide();
		$('#name').focus();
		return false;
	}else{
		$(".error").hide();
	}
	return true;
}
</script>
{/block}